package com.yida.gwj.expend.service;

import java.util.List;
import java.util.Optional;
import java.util.function.Function;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.yida.gwj.api.domain.GwjMaintenanceFundsBusinessInner;
import com.yida.gwj.api.domain.dto.GwjExpendHouseAndOwnerDTO;
import org.springframework.context.annotation.EnableAspectJAutoProxy;

import com.yida.gwj.api.domain.GwjConfFlow;
import com.yida.gwj.api.domain.GwjFinanceAccountMain;
import com.yida.gwj.api.domain.GwjMaintenanceFundsBusinessInner;
import com.yida.gwj.api.domain.dto.GwjExpendHouseAndOwnerDTO;
import com.yida.gwj.api.domain.request.RemoteGwjFinanceAccountMainRequest;
import com.yida.gwj.common.domain.mq.MqSendResult;
import com.yida.gwj.common.enums.GwjBusinessFlagType;
import com.yida.gwj.expend.domain.GwjMaintenanceFundsBusiness;
import com.yida.gwj.expend.domain.GwjMaintenanceFundsBusinessBuild;
import com.yida.gwj.expend.domain.GwjMaintenanceFundsBusinessHouse;
import com.yida.gwj.expend.domain.dto.AllocatedAmountListDTO;
import com.yida.gwj.expend.domain.dto.AllocatedAmountSelectDTO;
import com.yida.gwj.expend.domain.dto.Application4ApprovalDTO;
import com.yida.gwj.expend.domain.dto.ApplicationReportDTO;
import com.yida.gwj.expend.domain.dto.Appropriate4ApproveDTO;
import com.yida.gwj.expend.domain.dto.ChangeSchemeDTO;
import com.yida.gwj.expend.domain.dto.ConfirmReceiptDTO;
import com.yida.gwj.expend.domain.dto.CostListDTO;
import com.yida.gwj.expend.domain.dto.FilingCertificateDTO;
import com.yida.gwj.expend.domain.dto.GwjMaintenanceFundsBusinessGetInfoDTO;
import com.yida.gwj.expend.domain.dto.GwjMaintenanceFundsBusinessListDTO;
import com.yida.gwj.expend.domain.dto.OneTimeNotificationDTO;
import com.yida.gwj.expend.domain.dto.StepConfigInfoDTO;
import com.yida.gwj.expend.domain.message.PreAcceptMessage;
import com.yida.gwj.expend.domain.message.PreAcceptSubmitMessage;
import com.yida.gwj.expend.domain.request.AllocatedAmountRequest;
import com.yida.gwj.expend.domain.request.BusinessProcessRequest;
import com.yida.gwj.expend.domain.request.EditFormRequest;
import com.yida.gwj.expend.domain.request.GwjMaintenanceFundsBusinessListRequest;
import com.yida.gwj.expend.domain.request.GwjMaintenanceFundsBusinessRequest;
import com.yida.gwj.expend.domain.request.HousesUnderBuildRequest;
import com.yida.gwj.expend.domain.request.SubmitRequest;
import com.yida.gwj.expend.enums.BusinessModuleTypeEnum;

/**
 * 公维金维修资金业务预受理接口
 *
 * @author lgp
 * @date 2023-02-20
 */
@EnableAspectJAutoProxy(exposeProxy = true)
public interface IGwjMaintenanceFundsBusinessService {
    /**
     * 查询公维金维修资金业务
     *
     * @param businessId 公维金维修资金业务主键
     * @return 公维金维修资金业务
     */
    GwjMaintenanceFundsBusinessGetInfoDTO getInfoDetails(Long businessId);

    /**
     * 根据flowId查询业务流程
     *
     * @param flowId 业务流程主键
     * @return 业务流程
     */
    GwjConfFlow selectGwjConfFlowByFlowId(Long flowId);

    /**
     * 查询公维金维修资金业务列表
     *
     * @param maintenanceFundsBusinessListRequest 公维金维修资金业务
     * @return 公维金维修资金业务集合
     */
    List<GwjMaintenanceFundsBusinessListDTO> getGwjMaintenanceFundsBusinessList(GwjMaintenanceFundsBusinessListRequest maintenanceFundsBusinessListRequest);

    /**
     * 查询公维金维修资金业务列表
     *
     * @param gwjMaintenanceFundsBusiness 公维金维修资金业务
     * @return 公维金维修资金业务集合
     */
    List<GwjMaintenanceFundsBusiness> selectGwjMaintenanceFundsBusinessList(GwjMaintenanceFundsBusiness gwjMaintenanceFundsBusiness);

    /**
     * 新增公维金维修资金业务
     *
     * @param gwjMaintenanceFundsBusiness 公维金维修资金业务
     * @return 结果
     */
    GwjMaintenanceFundsBusiness insertGwjMaintenanceFundsBusiness(GwjMaintenanceFundsBusiness gwjMaintenanceFundsBusiness);

    /**
     * 修改公维金维修资金业务
     *
     * @param gwjMaintenanceFundsBusiness 公维金维修资金业务
     * @return 结果
     */
    GwjMaintenanceFundsBusiness updateGwjMaintenanceFundsBusiness(GwjMaintenanceFundsBusiness gwjMaintenanceFundsBusiness);

    /**
     * 取件
     *
     * @param businessProcessRequest
     * @return int
     */
    int takeParts(BusinessProcessRequest businessProcessRequest);

    /**
     * 分摊金额-已选择
     *
     * @param allocatedAmountRequest
     * @return AllocatedAmountSelectDTO
     */
    AllocatedAmountSelectDTO allocatedAmountSelect(AllocatedAmountRequest allocatedAmountRequest);

    /**
     * 预受理审核
     *
     * @param bizId 商业标识
     * @return int
     */
    PreAcceptMessage preAcceptExamine(Long bizId);

    /**
     * 预受理审核
     * 
     * 20230519
     *
     * @param bizId 商业标识
     * @return int
     */
    MqSendResult preAcceptExamineByBizId(Long bizId);

    /**
     * 二次补件审核
     *
     * @param businessId
     * @return int
     */
    int preAcceptSecondExamine(Long businessId);

    /**
     * 查询公维金维修资金业务列表
     *
     * @param maintenanceFundsBusinessRequest 公维金维修资金业务
     * @return 公维金维修资金业务集合
     */
    GwjMaintenanceFundsBusiness getGwjMaintenanceFundsBusiness(GwjMaintenanceFundsBusinessRequest maintenanceFundsBusinessRequest);

    /**
     * 首次附件退件
     *
     * @param businessProcessRequest
     * @return int
     */
    int preAcceptRetreat(BusinessProcessRequest businessProcessRequest);

    /**
     * 查询公维金维修资金业务
     *
     * @param businessId 公维金维修资金业务主键
     * @return 公维金维修资金业务
     */
    GwjMaintenanceFundsBusiness selectGwjMaintenanceFundsBusinessByBusinessId(Long businessId);

    /**
     * 获取步骤按钮权限信息
     *
     * @param businessFlagTypes 业务标志类型
     * @return 查询业务基础信息
     */
    StepConfigInfoDTO getStepConfigInfo(GwjBusinessFlagType... businessFlagTypes);

    /**
     * 使用申请-资金分摊-未选中列表
     *
     * @param allocatedAmountRequest 请求
     * @return 公维金维修资金业务
     */
    List<GwjMaintenanceFundsBusinessHouse> allocatedAmountCancelList(AllocatedAmountRequest allocatedAmountRequest);

    /**
     * 获取改造方案
     *
     * @param businessId 业务标识
     * @return {@link ChangeSchemeDTO}
     */
    ChangeSchemeDTO getTransformationPlan(Long businessId);

    /**
     * 查看申请报告
     *
     * @param businessId
     * @return AllocatedAmountSelectDTO
     */
    ApplicationReportDTO getApplicationReport(Long businessId);

    /**
     * delete4Save
     *
     * @param businessDelete2SaveRequest 业务delete2保存请求
     * @param bizId 业务标识
     * @param deleteModuleTypeEnums 删除模块类型枚举
     * @return int
     */
    Optional<GwjMaintenanceFundsBusiness> delete4Save(Function<Long, Optional<PreAcceptSubmitMessage>> businessDelete2SaveRequest, Long bizId, BusinessModuleTypeEnum... deleteModuleTypeEnums);

    /**
     * 确认受理
     *
     * @param submitRequest 确认受理
     * @return int
     */
    int confirmAcceptance(SubmitRequest submitRequest);

    /**
     * 提交
     *
     * @param submitRequest 第一次检查
     * @return int
     */
    int submit(SubmitRequest submitRequest);

    /**
     * 确认收件
     *
     * @param confirmReceipt 公维金维修资金业务
     * @return int
     */
    int confirmReceipt(ConfirmReceiptDTO confirmReceipt);

    /**
     * 取消收件
     *
     * @param attachmentId
     * @return int
     */
    int cancelReceipt(Long attachmentId);

    /**
     * 回退
     *
     * @param submitRequest 业务标识
     * @return int
     */
    int fallback(SubmitRequest submitRequest);

    /**
     * 一次性告知单
     *
     * @param businessId 业务标识
     * @return int
     */
    OneTimeNotificationDTO oneTimeNotification(Long businessId);

    /**
     * 编辑表单
     *
     * @param editFormRequest
     * @return int
     */
    int editForm(EditFormRequest editFormRequest);

    /**
     * 查看申请报批
     *
     * @param bizId 业务标识
     * @return {@link Application4ApprovalDTO}
     */
    Application4ApprovalDTO getApplication4Approval(Long bizId);

    /**
     * 获取已选中楼栋信息
     *
     * @param bizId 商业标识
     * @return 获取已选中楼栋信息
     */
    List<GwjMaintenanceFundsBusinessBuild> getSelectBuilds(Long bizId);

    /**
     * 获取楼栋下房屋信息
     *
     * @param housesUnderBuildRequest 房子在构建请求
     * @return 楼栋下房屋信息
     */
    List<GwjMaintenanceFundsBusinessHouse> getHouseList(HousesUnderBuildRequest housesUnderBuildRequest);

    /**
     * 获取使用拨付申请表
     *
     * @param bizId 业务标识
     * @return {@link Application4ApprovalDTO}
     */
    Appropriate4ApproveDTO getAppropriate4Approval(Long bizId);

    /**
     * 生成财务流水
     *
     * @param bizId 业务标识
     * @return {@link Application4ApprovalDTO}
     */
    int generateFinancialJournal(Long bizId);

    /**
     * 获取总账流水
     *
     * @param mainRequest 主要要求
     * @return {@link List}<{@link GwjFinanceAccountMain}>
     */
    List<GwjFinanceAccountMain> selectGwjFinanceAccountMainList(RemoteGwjFinanceAccountMainRequest mainRequest);

    /**
     * 获得业务模块列表
     *
     * @param bizId 维修基金业务
     * @return {@link PreAcceptSubmitMessage}
     */
    PreAcceptSubmitMessage getBusinessModules(Long bizId);

    /**
     * 导出房屋数据
     *
     * @param allocatedAmountRequest
     * @return 楼栋下房屋信息
     */
    List<AllocatedAmountListDTO> exportHouseList(AllocatedAmountRequest allocatedAmountRequest);

    /**
     * 分摊清册
     *
     * @param bizId 商业标识
     * @return {@link List}<{@link CostListDTO}>
     */
    abstract List<CostListDTO> costList(Long bizId);

    /**
     * 打印备案证明
     *
     * @param bizId 业务标识
     * @return {@link FilingCertificateDTO}
     */
    FilingCertificateDTO printFilingCertificate(Long bizId);

    /**
     * 内部获取公维金维修资金业务
     *
     * @param bizId 业务主键
     * @return
     */
    GwjMaintenanceFundsBusinessInner innerGetInfo(Long bizId);

    /**
     * 查询业主征求意见材料-房屋业主投票列表
     *
     * @param outServerIdentification 业务标识
     * @return
     */
    List<GwjExpendHouseAndOwnerDTO> selectHouseAndOwnerVoteInfo(String outServerIdentification);

    // ---------------------------------------新增功能区 hmh start--------------------------------------------------
    /**
     * 新增公维金维修资金业务
     *
     * 20230714
     *
     * @param gwjMaintenanceFundsBusiness 公维金维修资金业务
     * @return 结果
     */
    int insertGwjMaintenanceFundsBusinessCustom(GwjMaintenanceFundsBusiness gwjMaintenanceFundsBusiness);

    /**
     * 修改公维金维修资金业务
     *
     * 20230714
     *
     * @param gwjMaintenanceFundsBusiness 公维金维修资金业务
     * @return 结果
     */
    int updateGwjMaintenanceFundsBusinessCustom(GwjMaintenanceFundsBusiness gwjMaintenanceFundsBusiness);

    /**
     * 批量取消收件
     * 
     * 20230717
     *
     * @param attachmentId
     * @return int
     */
    int batchCancelReceipt(Long[] attachmentId);
    // ---------------------------------------新增功能区 hmh end--------------------------------------------------

    /**
     * 修改公维金维修资金业务
     *
     * @param gwjMaintenanceFundsBusiness 公维金维修资金业务
     * @return 结果
     */
    GwjMaintenanceFundsBusiness updateGwjMaintenanceFundsBusinessInner(GwjMaintenanceFundsBusiness gwjMaintenanceFundsBusiness);

    /**
     * 获取申请报批信息-业主表决情况
     * @param outServerIdentification 外网业务标识
     * @return
     */
    JSONObject getApplication4ApprovalOwnerCheck(String outServerIdentification, Integer bizFlagId);

    /**
     * 步骤回调
     *
     * @param business
     * @return
     */
    public String resultNotify(GwjMaintenanceFundsBusiness business);

    /**
     * 财务对账
     * @param bizId 业务主键
     * @return
     */
    Boolean financeCheck(Long bizId);

    /**
     * 基础房屋扣费（案例完结）
     * @param bizId 业务主键
     * @return
     */
    Boolean baseHouseCharging(Long bizId);
}
